from pydantic import BaseModel, ConfigDict
from typing import Optional


# 创建Test的Pydantic模型，用于请求和响应数据的验证

# 基础Schema
class TestBase(BaseModel):
    name: str
    age: Optional[int] = None


# 创建Test时的Schema
class TestCreate(TestBase):
    pass


# 更新Test时的Schema
class TestUpdate(TestBase):
    name: Optional[str] = None  # 更新时字段都是可选的
    age: Optional[int] = None


# 用于响应的Schema (包含ID等数据库字段)
class Test(TestBase):
    id: int

    model_config = ConfigDict(from_attributes=True)  # 新写法